Saving/opening images
In the new BorlandBase, I added two methods to save images:
You will need to import java.io.File;
saveImage(int x, int y, int width, int height)
saveImage(int x, int y, int width, int height,File file)
To use the first, just put it anywhere like (probably when a button is pressed:
saveImage(toolPanel.getWidth(),0, getWidth()-toolPanel.getWidth(),toolPanel.getHeight());
To use the second just put it anywhere like (probably when a button is pressed) and then have a file chooser open up.:
JFileChooser fileChooser = new JFileChooser();
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
saveImage(toolPanel.getWidth(),0, getWidth()-toolPanel.getWidth(),drawingPanel.getHeight(),selectedFile );
}
}
To load an image (it must be in same directory as project, just use drawImage as before.
JFileChooser fileChooser = new JFileChooser();
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
drawImage(selectedFile.getName(),toolPanel.getWidth(),0);
}
|